﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ZedGraph;

namespace TP_EDA_5847
{
    public partial class Graph : Form
    {
        public string name;
        PointPairList list2;

        /// <summary>
        /// Graph constructor
        /// </summary>
        /// <param name="name">Title of the graph</param>
        /// <param name="typeOfGraph">0 = X/Y axis graph
        ///                           1 = Test Time/Num elementes graph</param>
        public Graph(string name, int typeOfGraph)
        {
            this.name = name;
            InitializeComponent();
            CreateGraph(typeOfGraph);
        }

        /// <summary>
        /// Create the Graph
        /// </summary>
        /// <param name="type">0 = X/Y axis graph
        ///                           1 = Test Time/Num elementes graph</param>
        public void CreateGraph(int type)
        {
            GraphPane myPane = zedGraphControl2.GraphPane;

            // Set the titles and axis labels
            myPane.Title.Text = this.name;
            if (type == 0)
            {
                myPane.XAxis.Title.Text = "X";
                myPane.YAxis.Title.Text = "Y";
            }

            if (type == 1) {
                myPane.XAxis.Title.Text = "Num Elements";
                myPane.YAxis.Title.Text = "Time";
            }

            // Make up some data points from the Sine function
            PointPairList list1 = new PointPairList();
            // Add ponits from list
            if(type == 0){
                foreach(No no in Program.nos)
                {
                    list1.Add(no.value[0], no.value[1]);
                }
            }
            // Add values and Keys from a dictionary
            if (type == 1)
            {
                foreach (KeyValuePair<int, int> point in Program.points)
                {
                    list1.Add(point.Value, point.Key);
                }
            }
            // Generate a blue curve with Plus symbols,
            LineItem myCurve1 = myPane.AddCurve("Pontos", list1, Color.Blue, SymbolType.Circle);
            myCurve1.Line.IsVisible = false;

            // Fill the pane background with a color gradient
            myPane.Fill = new Fill(Color.White, Color.FromArgb(220, 220, 255), 45F);

            //Make the MajorGrids of Axes visible
            myPane.XAxis.MajorGrid.IsVisible = true;
            myPane.YAxis.MajorGrid.IsVisible = true;

            // Calculate the Axis Scale Ranges
            zedGraphControl2.AxisChange();
        }

        /// <summary>
        /// Add addictional points to the graph
        /// </summary>
        /// <param name="name">Title of the graph</param>
        /// <param name="typeOfGraph">0 = X/Y axis graph
        ///                           1 = Test Time/Num elementes graph</param>
        public void addPoint(List<int> point, List<int> closestPoint)
        {
            GraphPane myPane2 = zedGraphControl2.GraphPane;
            list2 = new PointPairList();
            list2.Add(point[0], point[1]);
            list2.Add(closestPoint[0], closestPoint[1]);
            LineItem _myCurve2 = myPane2.AddCurve("Closest point", list2, Color.Red, SymbolType.Star);

            // Calculate the Axis Scale Ranges
            zedGraphControl2.AxisChange();
        }
    }
}
